//ÇÐ»»·ÖÀà
var tabId = 0;
var busiType=0;
var applyTime =getToday();

$(function(){
    $("#startApplyTime").val(getToday());
    $("#dstartApplyTime").val(getToday());
    getBedUserInfo(1);
});




//²éÑ¯
$("#btnSearchBedApply").on("click",function(){
    isPostBack=true;
    getBedUserInfo(1);
});
$("#btnSearchFaultAlarm").on("click",function(){
        isPostBack=true;
        getBedUserInfo(1);
    });
$("#myTabs li").on("click", function () {
    busiType=$(this).index();
    $(".bg-date").val("");
    getBedUserInfo(1);
});
//»ñÈ¡´²Î»·ÖÅäÐÅÏ¢
function getBedUserInfo(pageIndex){
    var time = $("#startApplyTime").val();
    if(busiType==1){
        $.getJSON('/cwp/src/json/apartment/journal/bed_008.json',function(data){
            var loaderRealtyTab = new LoaderTable("faultAlarmLoader","faultApplyTab","/cwp/front/sh/bedapplyAnalysis!execute","uid=bedapplyAnalysis008",pageIndex,8,bedUser,"","frmSearch");
            // loaderRealtyTab.Display();
            bedUser(data); 
        })
    }
    else if(busiType==0){
        $.getJSON('/cwp/src/json/apartment/journal/bed_010.json',function(data){
            getinfo(data);
        })
        // PostForm("/cwp/front/sh/bedapplyAnalysis!execute","uid=bedapplyAnalysis010&applyTime="+time,"",getinfo,"","fromSearch1");
    }

}

function paginationCallback(page_index){
    if(tabId == 0){
        if(!isPostBack) getBedUserInfo(page_index+1);
    }else{
        if(!isPostBack) getHistoryInfo(page_index+1);
    }
}
function getinfo(result){
    if(result.returnCode==1){
        $("#allNum").text("");
        $("#allRate").text("");
        $("#allGraNum").text("");
        $("#allAmNum").text("");
        $("#manAmNum").text("");
        $("#womanAmNum").text("");
        $("#allAmRate").text("");
        $("#manAmRate").text("");
        $("#womanAmRate").text("");
        $("#allPmNum").text("");
        $("#manPmNum").text("");
        $("#womanPmNum").text("");
        $("#allPmRate").text("");
        $("#manPmRate").text("");
        $("#womanPmRate").text("");
    }
    else if(result.returnCode==0){
        $("#allNum").text(result.bean.allNum);
        $("#allRate").text((result.bean.allRate*100).toFixed(0)+"%");;
        $("#allGraNum").text(result.bean.allGraNum);
        $("#allAmNum").text(result.bean.allAmNum);
        $("#manAmNum").text(result.bean.manAmNum);
        $("#womanAmNum").text(result.bean.womanAmNum);
        $("#allAmRate").text((result.bean.allAmRate*100).toFixed(0)+"%");
        $("#manAmRate").text((result.bean.manAmRate*100).toFixed(0)+"%");
        $("#womanAmRate").text((result.bean.womanAmRate*100).toFixed(0)+"%");
        $("#allPmNum").text(result.bean.allPmNum);
        $("#manPmNum").text(result.bean.manPmNum);
        $("#womanPmNum").text(result.bean.womanPmNum);
        $("#allPmRate").text((result.bean.allPmRate*100).toFixed(0)+"%");
        $("#manPmRate").text((result.bean.manPmRate*100).toFixed(0)+"%");
        $("#womanPmRate").text((result.bean.womanPmRate*100).toFixed(0)+"%");
    }
}
function bedUser(result){

    var thead="<thead>"+
       "<tr>" +
        "<th>部门名称</th>" +
        "<th>总人数</th>" +
        "<th>入住率</th>" +
        "<th>中午入住人数</th>" +
        "<th>中午入住率</th>" +
        "<th>晚上入住人数</th>" +
        "<th>晚上入住率</th>" +
        "</tr>" +
        "</thead>";
    var tbodys= "<tbody>";
    for(var i=0;i<result.beans.length;i++) {
        var bedUser = result.beans[i];
        tbodys += "<tr>" +
            "<td>" +  bedUser.deptName + "</td>" +
            "<td>" +  bedUser.pNum + "</td>" +
            "<td>" +  (bedUser.checkInRate*100).toFixed(0) + "%</td>" +
            "<td>" +  bedUser.pAmNum + "</td>" +
            "<td>" +  (bedUser.checkInAmRate*100).toFixed(0) + "%</td>" +
            "<td>" +  bedUser.pPmNum + "</td>" +
            "<td>" +  (bedUser.checkInPmRate*100).toFixed(0) + "%</td>" +
            "</tr>"
    }
    tbodys+= "</tbody>";
    $("#faultApplyTab").html(thead+tbodys);

}
//»ñÈ¡µ±Ç°ÈÕÆÚ
function getToday(){
    var today = "";
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    today = year + "-" + (month<10?"0"+month:month) + "-" + (day<10?"0"+day:day);
    return today;
}
